package config

import (
	"fmt"
	"strings"

	"github.com/spf13/viper"
)

var CONF *viper.Viper

func InitConfiguration(path string) error {
	p := strings.Split(path, ".")

	CONF = viper.New()
	CONF.SetConfigName(p[0])
	CONF.SetConfigType(p[1])
	CONF.AddConfigPath(".")

	if err := CONF.ReadInConfig(); err != nil {
		return fmt.Errorf("parse configuration failed: %v", err)
	}

	return nil
}
